
#include <iostream>
using namespace std;
///////////////////////////////捕获变量/////////////////////////////////////
/*!
  1.捕获当前函数中的局部非static变量,对于局部static变量以及函数外声明的名字可以直接在函数体中使用
  2.值捕获,相当于定义值的类型;引用捕获应该于定义了捕获的引用
*/
int ga = 10;
void labmbda1(int& rb) {
    int la = 3;
    static int lsc = 5;
    auto ret = [=,&rb ](int fa) throw()->bool {
        rb = 5;
        cout << "ga=" << ga << "\trb=" << rb << "\tla=" << la << "\tlsc=" << lsc
             << "\tfa=" << fa << endl;
        return 0;
    };

    bool lret = ret(5);
    cout << "ret:" << lret << endl;
}


////////////////////////////////函数指针转换///////////////////////////////////////////////////
typedef int (__stdcall *Func)(int);

void func(Func f)
{
  cout<<"Func value:"<<f(23)<<endl;
}
class lambda_xxx
{
  public:
    int operator()(int i) const
    {
      return i;
    }

    __stdcall static  int lambda_invoker(int i)
    {
      return (static_cast<lambda_xxx*>(nullptr))->operator()(i);
    }

    operator Func()
    {
      return &lambda_invoker;
    }


};
#include <vector>
#include <algorithm>
void testLambda() {

  //测试lambda捕获变量情况
  int rb = 10;
  cout<<"rb:"<<rb<<endl;
   labmbda1(rb);
  cout<<"rb1:"<<rb<<endl;
  cout<<"///////////1 end//////////////////"<<endl;

  lambda_xxx lx = lambda_xxx();

  Func fc = lx.operator Func();

  func(fc);
  cout<<"///////////2 end//////////////////"<<endl;

  func([](int i){
    return i;
  });

   cout<<"///////////3 end//////////////////"<<endl;
  []{
    cout<<"hello lambdas"<<endl;
  }();
  // l();
  cout<<"///////////4 end//////////////////"<<endl;
  std::vector<int> v1{5,28,50,83,70,590};

 cout<<"v1:";
  for(auto i: v1)
  {
    cout<<i<<" ";
  }
   int x = 30, y = 100;
   auto ite = remove_if(v1.begin(),v1.end(),
   [x,y](int n)
   {
     return (x<n && n<y);
   });

   cout<<"v2:";
  for(auto i: v1)
  {
    cout<<i<<" ";
  }

  v1.erase(ite,v1.end());

 cout<<"v3:";
  for(auto i: v1)
  {
    cout<<i<<" ";
  }




}